package com.wei.spring.web.user.exception;

import com.wei.spring.web.user.model.vo.ResultData;
import com.wei.spring.web.user.util.ResultUtil;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@Component
@ControllerAdvice
public class UnifiedExceptionHandler {

    /**
     * 业务异常
     *
     * @param e 异常
     * @return 异常结果
     */
    @ExceptionHandler(value = BusinessException.class)
    @ResponseBody
    public ResultData handleBusinessException(BusinessException e) {
        return ResultUtil.getError(e);
    }


    /**
     * 未定义其他异常
     *
     * @param e 异常
     * @return 异常结果
     */
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public ResultData handleException(Exception e) {
        return ResultUtil.getError();
    }

}
